<!DOCTYPE html>
<html>
	<head>
		<title>Just For Fun</title>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
		<meta name="renderer" content="webkit" />
		<meat name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
	</head>
	<body onload="main()">
		<script type="text/javascript">
			function main() {
				var c = 0;
				for (var k in alogrithms) {
					var alogrithm = alogrithms[k];
					var result = alogrithm(7);
					c++;
					console.log('Alogrithm ' + k + ':');
					console.log(result);
				}
				console.log('Total ' + c + ' methods.');
			}

			var kits = {
				nStr: (c, len) => {
					var builder = [];
					for (var i=0; i<len; i++)
						builder.push(c);
					return builder.join('');
				},

				map: (array, f) => {
					var tmp = [];
					for (var i=0; i<array.length; i++)
						tmp.push(f(array[i]));
					return tmp;
				},

				cat: (array1, array2) => {
					var tmp = [];
					for (var i=0; i<array1.length; i++)
						tmp.push(array1[i]);
					for (var i=0; i<array2.length; i++)
						tmp.push(array2[i]);
					return tmp;
				}
			};

			var alogrithms = {
				tr00: n => {
					var builder = [];
					builder.push('      *');
					builder.push('     ***');
					builder.push('    *****');
					builder.push('   *******');
					builder.push('  *********');
					builder.push(' ***********');
					builder.push('*************');
					return builder.join('\r\n');
				},

				tr0 : n => {
					var src = [];
					src.push('          *');
					src.push('         ***');
					src.push('        *****');
					src.push('       *******');
					src.push('      *********');
					src.push('     ***********');
					src.push('    *************');
					src.push('   ***************');
					src.push('  *****************');
					src.push(' *******************');
					src.push('*********************');

					var take = x => {
						var tmp = [];
						for (var i=0; i<x; i++)
							tmp[i] = src[i];
						return tmp;
					};

					var cut = (row, m) => row.substring(m);

					return kits.map(take(n), x => cut(x, 11 - n)).join('\r\n');
				},

				tr1 : n => {
					var builder = [];
					for (var i=0; i<n; i++)
						builder.push(kits.nStr(' ', n-i-1) + kits.nStr('*', 2*i+1));

					return builder.join('\r\n');
				},

				tr10: n => {
					var builder = [];
					var print = c => builder.push(c);

					for (var i=0; i<n; i++) {
						for (var j=0; j<n-i-1; j++)
							print(' ');
						for (var j=0; j<2*i+1; j++)
							print('*');
						print('\r\n');
					}

					return builder.join('');
				},

				tr21 : n => {
					var builder = [];
					var w = n-1, s = 1;
					while (w>=0) {
						builder.push(kits.nStr(' ', w) + kits.nStr('*', s));
						w -= 1;
						s += 2;
					}
					return builder.join('\r\n');
				},

				tr2 : n => {
					var iterator = (w, s) => {
						var white = w, star = s;

						var obj = {};
						var html = [];

						obj.next = () => {
							html.push(kits.nStr(' ', white) + kits.nStr('*', star));
							white -= 1;
							star += 2;
							return white >= 0;
						};

						obj.build = () => html.join('\r\n');

						return obj;
					};

					var iter = iterator(n-1, 1);
					while (iter.next());
					return iter.build();
				},

				tr3 : n => {
					var make = m => {
						if (m == 0)
							return [];

						var last = make(m-1);
						var mapped = kits.map(last, x => x + '**');
						var head = [kits.nStr(' ', m-1) + '*'];
						return kits.cat(head, mapped);
					};

					return make(n).join('\r\n');
				},

				tr30 : n => {
					var make = m => {
						if (m == 0)
							return [];

						var last = make(m-1);
						var mapped = kits.map(last, x => ' ' + x);
						var tail = [kits.nStr('*', 2*m-1)];
						return kits.cat(mapped, tail);
					};

					return make(n).join('\r\n');
				},

				tr4: n => {
					var builder = [];
					var r, k;
					var loops = {
						S: () => {
							r = 0; k = 0;
							return 'W';
						},

						W: () => {
							if (k>0)
								builder.push(' ');
							return ++k < n - r ? 'W' : 'C';
						},

						C: () => {
							builder.push('*');
							return ++k < n + r + 1 ? 'C' : 'R';
						},

						R: () => {
							builder.push('\r\n');
							k = 0;
							return ++r < n ? 'W' : 'Z'
						}
					};

					var state = 'S';
					while (state != 'Z')
						state = loops[state]();

					return builder.join('');
				}
			};
		</script>
	</body>
</html>